package io.renren.modules.behavior.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.behavior.dao.UserBehaviorLogDao;
import io.renren.modules.behavior.entity.UserBehaviorLogEntity;
import io.renren.modules.behavior.service.UserBehaviorLogService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("userBehaviorLogService")
public class UserBehaviorLogServiceImpl extends ServiceImpl<UserBehaviorLogDao, UserBehaviorLogEntity> implements UserBehaviorLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        QueryWrapper<UserBehaviorLogEntity> queryWrapper = new QueryWrapper<>();
        if (Query.STATUS_ACTIVED.equals(params.get(Query.STATUS))) {
            queryWrapper.eq("status", 1);
        }

        IPage<UserBehaviorLogEntity> page = this.page(
                new Query<UserBehaviorLogEntity>().getPage(params),
                queryWrapper
        );


        return new PageUtils(page);
    }

    @Override
    public UserBehaviorLogEntity queryIsLike(Long userId, Long itemId) {
        QueryWrapper<UserBehaviorLogEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1)
                .eq("user_id", userId)
                .eq("item_id", itemId)
                .eq("user_behavior_type", 1);

        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public UserBehaviorLogEntity queryIsCollection(Long userId, Long itemId) {
        QueryWrapper<UserBehaviorLogEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1)
                .eq("user_id", userId)
                .eq("item_id", itemId)
                .eq("user_behavior_type", 2);

        return baseMapper.selectOne(queryWrapper);
    }

}